package org.jeecg.modules.system.service.impl;

import org.jeecg.modules.system.service.SysUserRoleService;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class SysUserRoleServiceImpl2 extends JdbcDaoSupport implements SysUserRoleService {

    @Override
    public List<String> getRoleByUserName(String username) {

        String sql="select role_code from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username='"+username+"'))";

        List list=this.getJdbcTemplate().query(sql,new roleByUser());

        return list;
    }

    class roleByUser implements RowMapper<String> {

        @Override
        public String mapRow(ResultSet rs, int rowNum) throws SQLException {

            String role_code=rs.getString("role_code");

            return role_code;
        }
    }

    @Override
    public List<String> getRoleIdByUserName(String username) {

        String sql="select id from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username='"+username+"'))";

        List list=this.getJdbcTemplate().query(sql,new roleById());

        return list;
    }

    class roleById implements RowMapper<String> {

        @Override
        public String mapRow(ResultSet rs, int rowNum) throws SQLException {

            String id=rs.getString("id");

            return id;
        }
    }

    @Override
    public void deleteByUserId(String userId) {

    }
}
